package com.log4j;

import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.lf5.util.Resource;
import org.apache.log4j.lf5.util.ResourceUtils;
import org.apache.log4j.xml.DOMConfigurator;

/**
 * @PACKAGE_NAME: com.log4j
 * @NAME: Log4jBefore
 * @USER: 黄剑
 * @DATE: 2023/12/4
 * @PROJECT_NAME: all_my_guess
 * @说明：这个类研究加载路径
 */
public class Log4jBefore {
   // @Before
    public void before(){
        /**
         * 如果没有指定配置文件路径,log4j会主动加载类路径的log4j.xml或log4j.properties
         * 两个都存在那么xml优先
         */
//        主动加载config中的log4j.properties
        PropertyConfigurator.configure(
                ResourceUtils.getResourceAsURL(this,new Resource("config/log4j.properties"))
        );
//        主动加载config中的log4j.xml
        DOMConfigurator.configure(
                ResourceUtils.getResourceAsURL(this,new Resource("config/log4j.xml"))
        );
    }
}
